<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'uploadbrand.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
<!-- swfupload need css begin-->
	<link href="swfupload/default.css" rel="stylesheet"/>
<!-- swfupload need css end-->
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- swfupload need js  begin-->
	<script type="text/javascript" src="swfupload/swfupload.js"></script>
	<script type="text/javascript" src="swfupload/swfupload.queue.js"></script>
	<script type="text/javascript" src="swfupload/fileprogress.js"></script>
	<script type="text/javascript" src="swfupload/handlers5.js"></script>
<!-- swfupload need js end-->
	<script type="text/javascript">
		var swfu;
		window.onload = function() {
			var settings = {
				flash_url : "swfupload/swfupload.swf",
				 upload_url: "UpLoadBrandAction",
				//post_params: {"brand":$("#brandselect").val()},
				file_size_limit : "100 MB",
				file_post_name: "swfupload",
				file_types : "*.*",
				file_types_description : "All Files",
				file_upload_limit : 1,
				file_queue_limit : 0,
				custom_settings : {
					progressTarget : "fsUploadProgress",
					cancelButtonId : "btnCancel"
				},
				debug: false,

				// Button settings
				//button_image_url: "img/51.png",
				button_width: "80",
				button_height: "29",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: '<span class="theFont">选取文件</span>',
				button_text_style: ".theFont { font-size: 16; }",
				button_text_left_padding: 12,
				button_text_top_padding: 3,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,
				queue_complete_handler : queueComplete	// Queue plugin event
			};
				swfu = new SWFUpload(settings);
	     };
	     function upload (){
	     	//动态设置PostParams参数
	     	if($("#newCarName").val()==null||$("#newCarName").val()==""){
	     		alert("您还没输入车名");
	     	}else if($("#brandselect").val()=="xx"){
	     		alert("您未选择车型");
	     	}else if(swfu.getStats().files_queued === 0){
	     		alert("请选择上传图片");
	     	}else{
	     		$.post("checkTheBrandSeriesAction",{"newCarName":$("#newCarName").val(),"brandId":$("#brandselect").val()},function(data){
	     				if(data=="true"){
	     					alert("这个品牌的车型已经存在");
	     					$("#newCarName").val("");
	     					$("#newCarName").focus();
	     				}else if(data=="false"){
	     					var postobj = {"brand":$("#brandselect").val(),"newCarName":$("#newCarName").val()};
	            			swfu.setPostParams(postobj);
		     				swfu.startUpload();
	     				}
	     		});
	     	}
	     }
	</script>
  </head>
 <body style="margin-top: 0px;">

<div id="content" style="width: 500px; height: 300px;position: absolute; left: 200px; top:50px;">
			<h2>增加新的车型</h2>
			
				<div>
					新增车型名：<input type="text" name="newCarName" id="newCarName">
				</div>
				<div class="fieldset flash" id="fsUploadProgress" >
					<span class="legend"></span>
				</div>
			<div>
				<select name="brand"  id="brandselect" style="width: 135px;">
					<option value="xx">--请选择车系列--</option>
					<c:forEach items="${brands}" var="brand">
						<option value="${brand.brandsId}">${brand.brandsName}</option>
					</c:forEach>
				</select>
			</div>
			<!-- <div id="divStatus">0 Files Uploaded</div> -->
			<div>
				<span id="spanButtonPlaceHolder"></span>
				<input id="btnCancel" type="button" value="删除未上传的文件" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
				<input type="button" value="提交" onclick="upload()">
			</div>
</div>

</body>
</html>
